package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.entity.OrderDetail;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.mapper.OrderDetailMapper;
import com.itheima.reggie.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service
public class OrderDetailServiceImpl implements OrderDetailService {
    
    @Autowired
    private OrderDetailMapper mapper;

    /**
     * 移动端--根据订单id查询订单详情
     *
     * @param orderId 订单id
     * @return  商品订单详情
     */
    @Override
    public List<OrderDetail> findByOrderId(String orderId) {
        //设置查询条件
        LambdaQueryWrapper<OrderDetail> lqw = new LambdaQueryWrapper<>();
        lqw.eq(orderId != null,OrderDetail::getOrderId,orderId);
        //执行查询
        return mapper.selectList(lqw);
    }

    /**
     * 添加订单详情对象
     *
     * @param orderDetail
     * @return
     */
    @Override
    public int add(OrderDetail orderDetail) {
        return mapper.insert(orderDetail);
    }
}
